package base.IO流;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class 拷贝文件夹 {
    /*考虑子文件*/
    public static void main(String[] args) throws IOException {
        File scr = new File("D:\\mods");
        File destin = new File("C:\\Users\\TUO\\Desktop\\拷贝数据");

        copy(scr,destin);
    }

    private static void copy(File src,File destin) throws IOException {
        destin.mkdir();
        File[] files = src.listFiles();
        if (files != null){
            for (File file : files){
                if (file.isFile()){
                    FileInputStream fis = new FileInputStream(file);
                    FileOutputStream fos = new FileOutputStream(new File(destin,file.getName()));//复制一份相同文件名路径
                    byte[] bytes = new byte[1024 * 1024];
                    int len;
                    while ((len = fis.read(bytes)) != -1){
                        fos.write(bytes,0,len);
                    }
                    fos.close();
                    fis.close();
                }else {
                    copy(file,new File(destin,file.getName()));
                }
            }
        }
    }
}
